package cn.dapeng.features;

import cn.dapeng.util.SleepingUtil;

import java.util.concurrent.TimeUnit;

public class Volatile_T02 {

    public /*volatile*/ static A a = new A();

    public static class A {
        public boolean running = true;
    }

    public static void m() {
        System.out.println("thread started");
        while (a.running) {

        }
        System.out.println("thread stopped");
    }

    public static void main(String[] args) {

        Thread thread = new Thread(Volatile_T02::m, "t1");

        thread.start();

        SleepingUtil.sleep(1, TimeUnit.SECONDS);

        a.running = false;
    }
}
